package com.yy.controller;

import base.Result;
import com.yy.pojo.param.UserLoginParam;
import com.yy.pojo.param.UserRegisterParam;
import com.yy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lyy
 * Date: 2021/12/13 11:33
 */
@RestController
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * @param param
	 * @return
	 */
	@PostMapping("/register")
	public Result register(@RequestBody @Validated UserRegisterParam param){
		userService.register(param);
		return Result.ok();
	}

	@PostMapping("/login")
	public Result login(@RequestBody @Validated UserLoginParam param){
		String token = userService.login(param);
		return Result.ok(token);
	}

	@GetMapping("/list")
	public Result list(){
		return Result.ok(userService.selectUserList());
	}

}
